﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Linq;

namespace TestExtensions
{
	public class TestAction : IHasSummary
	{
		#region Constructors

		public TestAction(XElement actionElement)
		{
			Element = actionElement;
			Name = Element.Element("AName").Value;
			this.LoadSummary();
			if (Element.Element("Step") != null)
			{
				Step = new TestStep(Element.Element("Step"));
			}
			if (Element.Element("AIter") != null)
			{
				Iterations = new ReadOnlyCollection<ActionIteration>(Element.Elements("AIter").Select(iterElement => new ActionIteration(iterElement)).ToList());
			}
		}

		#endregion

		#region Properties

		public XElement Element { get; private set; }

		public string Name { get; private set; }

		public Summary Summary { get; set; }

		public TestStep Step { get; private set; }

		public IEnumerable<ActionIteration> Iterations { get; private set; }

		#endregion
	}
}